<template>
  <div class="ssologin" v-loading="loading" element-loading-text="登录加载中..."></div>
</template>

<script>
import { tyLogin } from '@/api/login.js'
import { getAuth } from '@/utils/auth'

export default {
  name: "unifyLogin",
  data() {
    return {
      loading:true,
    };
  },
  created() {
    this.getUser();
  },
  methods: {
    getUser() {
        let username = this.$route.query.username;
        if(username){
          tyLogin({username}).then(res=>{
            console.log(res)
            if(res.status){
              localStorage.setItem("username",res.data.userName);
              localStorage.setItem("loginType", 'unifyLogin');
              this.$store.dispatch('user/login', {
                  token: res.data.token,
                  userType: res.data.userType,
                  roleId: res.data.roleId,
                  username:res.data.userName
              });
              // 获取按钮权限
              this.$store.dispatch("user/getAllBtn",res.data.roleId).then(btnList=>{
                  localStorage.setItem('btnList',JSON.stringify(btnList));
              });
              this.$router.push({
                  path: '/manager/index',
              });
            }else{
              window.open('https://xyjg.nantong.cn/sso/login?redirect=%2Fsso%2Fmenhu', '_blank')
            }
          });
        }else{
          window.open('https://xyjg.nantong.cn/sso/login?redirect=%2Fsso%2Fmenhu', '_blank')
        }
    },
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
.ssologin{height: 100vh;}
.scriptcon{text-align: center; font-size: 16px;}
</style>
